import * as mysql from "mysql";

export interface EquipmentRecord {
    id: string;
    equipmentName: string;
    type: string;
}

export function queryDdckDb() {
    const connection = mysql.createConnection({
        host: "localhost",
        user: "root",
        port: 3306,
        password: "123456",
        database: "ddckdb",
    });

    connection.connect();

    connection.query("SELECT Id as id, EquipmentName as equipmentName, Type as type FROM equipment", function (error, results: EquipmentRecord[], fields) {
        if (error) throw error;
        console.table(results);
        for (const record of results) {
            console.log("%s,\t%s,\t%s", record.id, record.equipmentName, record.type);
        }
    });

    connection.end();
}
